package com.zenithmind.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zenithmind.user.pojo.domain.TenantConfig;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 租户配置Mapper接口
 * 
 * @author ZenithMind
 * @since 2024-06-30
 */
@Mapper
public interface TenantConfigMapper extends BaseMapper<TenantConfig> {

    /**
     * 根据租户ID和配置键查询配置
     * 
     * @param tenantId 租户ID
     * @param configKey 配置键
     * @return 配置信息
     */
    @Select("SELECT * FROM tenant_config WHERE tenant_id = #{tenantId} AND config_key = #{configKey} AND is_deleted = 0")
    TenantConfig selectByTenantIdAndKey(@Param("tenantId") String tenantId, @Param("configKey") String configKey);

    /**
     * 根据租户ID查询所有配置
     * 
     * @param tenantId 租户ID
     * @return 配置列表
     */
    @Select("SELECT * FROM tenant_config WHERE tenant_id = #{tenantId} AND is_deleted = 0 ORDER BY config_key")
    List<TenantConfig> selectByTenantId(@Param("tenantId") String tenantId);

    /**
     * 查询系统配置
     * 
     * @param tenantId 租户ID
     * @return 系统配置列表
     */
    @Select("SELECT * FROM tenant_config WHERE tenant_id = #{tenantId} AND is_system = 1 AND is_deleted = 0 ORDER BY config_key")
    List<TenantConfig> selectSystemConfigs(@Param("tenantId") String tenantId);

    /**
     * 查询用户配置
     * 
     * @param tenantId 租户ID
     * @return 用户配置列表
     */
    @Select("SELECT * FROM tenant_config WHERE tenant_id = #{tenantId} AND is_system = 0 AND is_deleted = 0 ORDER BY config_key")
    List<TenantConfig> selectUserConfigs(@Param("tenantId") String tenantId);
}
